/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function doLogin() {
    $('loadingatloginform').innerHTML = 'Loading...';
    var loginRequest = new XMLHttpRequest();
    var username = $('usernamelogininput').value;
    var password = $('passwordlogininput').value;
    loginRequest.open("post", "loginhandler?", true);
    loginRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    loginRequest.send("username="+username+"&password="+password);
    loginRequest.onreadystatechange = function() {
        if (loginRequest.readyState == 4) {
            if (loginRequest.responseText == "username_not_exist")
                $('loadingatloginform').innerHTML = "The username '"+username+"' doesn't exist.";
            else if (loginRequest.responseText == "wrong_password")
                $('loadingatloginform').innerHTML = "Wrong password.";
            else if (loginRequest.responseText == "success")
                document.location = "signup.jsp";
            else
                $('loadingatloginform').innerHTML = "Server error.";
        }
    }
}
